<template>
  <div>
    <div style="display: flex;justify-content: space-between ;">
      <div>
        <el-input type="text" placeholder="请输入员工名进行搜索" prefix-icon="el-icon-search" v-model="empName"
          @keydown.enter.native="initEmps" clearable @clear="initEmps" :disabled="advanceSearchBtn"
          class="emp_search_inp"></el-input>
        <el-button type="primary" :disabled="advanceSearchBtn" icon="el-icon-search" @click="initEmps">搜索</el-button>
        <el-button type="primary" @click="advanceSearchBtn = !advanceSearchBtn">
          <i :class="advanceSearchBtn ? 'fa fa-angle-double-up' : 'fa fa-angle-double-down'" aria-hidden="true"></i>
          高级搜索
        </el-button>
      </div>
      <div>
        <el-upload style="display: inline-flex;margin-right: 8px;" :headers="hearder" action="/employee/basic/export"
          :show-file-list="false" :before-upload="beforeUpload" :on-success="onSuccess" :on-error="onError"
          :disabled="importDataDisables">
          <el-button type="success" :icon="uploadIcon" :disabled="importDataDisables">&nbsp;&nbsp;{{
            uploadText
          }}</el-button>

        </el-upload>
        <el-button type="success" icon="el-icon-download" @click="expostData">导出数据</el-button>
        <el-button type="primary" icon="el-icon-plus" @click="showAddEmp">添加员工</el-button>
      </div>

    </div>
    <!-- 高级搜索 -->
    <transition name="slide-fade">
      <div v-show="advanceSearchBtn"
        style="border: 1px solid #ebeef5;border-radius: 2px;box-sizing: border-box;padding: 5px;margin: 10px 0px;color: #606266;">

        <el-row>
          <el-col :span="5">
            政治面貌:
            <el-select clearable  size="mini" style="width: 130px;" v-model="searchValue.politicId" placeholder="政治面貌">
              <el-option v-for="(item, index) in politicsstatus" :key="index" :label="item.name"
                :value="item.id"></el-option>
            </el-select>
          </el-col>

          <el-col :span="4">
            名族:
            <el-select clearable  size="mini" class="add_emp_left" v-model="searchValue.nationId" placeholder="民族">
              <el-option v-for="(item, index) in nations" :key="index" :label="item.name" :value="item.id"></el-option>
            </el-select>
          </el-col>

          <el-col :span="4">
            职位:
            <el-select  clearable size="mini" class="add_emp_left" v-model="searchValue.posId" placeholder="职位">
              <el-option v-for="(item, index) in positions" :key="index" :label="item.name"
                :value="item.id"></el-option>
            </el-select>
          </el-col>

          <el-col :span="4">
            职称:
            <el-select clearable  size="mini" class="add_emp_left" v-model="searchValue.jobLevelId" placeholder="职称">
              <el-option v-for="(item, index) in joblevels" :key="index" :label="item.name"
                :value="item.id"></el-option>
            </el-select>
          </el-col>

          <el-col :span="7">
            聘用形式:
            <el-radio-group size="mini" v-model="searchValue.engageForm">
              <el-radio size="mini" label="劳动合同"></el-radio>
              <el-radio size="mini" label="劳务合同"></el-radio>
            </el-radio-group>
          </el-col>
        </el-row>

        <el-row style="margin-top: 10px;">

          <el-col :span="5">
            所属部门:
            <el-popover placement="bottom" title="请选择部门" width="200" trigger="manual" v-model="depVisible2">
              <el-tree :data="departments" :props="defaultProps" default-expand-all @node-click="searchHandleNodeClick">
              </el-tree>
              <div slot="reference" class="add_emp_dep" @click="showDepView2">
                <span class="dep_con">{{ inputDepName2 }}</span>
                <i class="el-icon-arrow-down ic_right"></i>
              </div>
            </el-popover>
          </el-col>

          <el-col :span="10">
            入职日期:
            <el-date-picker size="mini" v-model="searchValue.beginDateScope" type="daterange" value-format="yyyy-MM-dd"
              unlink-panels range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期">
            </el-date-picker>

          </el-col>

          <el-col :span="5" :offset="4">
            <el-button size="mini">取消</el-button>
            <el-button icon="el-icon-search" size="mini" type="primary" @click="initEmps('advanced')">搜索</el-button>
          </el-col>

        </el-row>



      </div>
    </transition>
    <!-- table 这一块 -->
    <div style="margin-top: 8px;margin-bottom: 10px;">
      <el-table :data="emps" stripe border v-loading="loading" style="width: 100%; text-align: center">
        <el-table-column type="selection" width="55"> </el-table-column>
        <el-table-column fixed="left" prop="name" label="姓名" width="70">
        </el-table-column>
        <el-table-column prop="workID" label="工号" width="100">
        </el-table-column>
        <el-table-column prop="gender" label="性别" width="50">
        </el-table-column>
        <el-table-column prop="joblevel.name" label="职称" width="100">
        </el-table-column>
        <el-table-column prop="position.name" label="职位" width="100">
        </el-table-column>
        <el-table-column prop="department.name" label="所属部门" width="100">
        </el-table-column>
        <el-table-column prop="birthday" label="生日" width="100">
        </el-table-column>
        <el-table-column prop="idCard" label="身份证号" width="160">
        </el-table-column>
        <el-table-column prop="wedlock" label="婚姻状况" width="70">
        </el-table-column>
        <el-table-column prop="nation.name" label="民族" width="50">
        </el-table-column>
        <el-table-column prop="politicsStatus.name" label="政治面貌" width="110">
        </el-table-column>
        <el-table-column prop="nativePlace" label="籍贯" width="110">
        </el-table-column>
        <el-table-column prop="phone" label="电话号码" width="100">
        </el-table-column>
        <el-table-column prop="address" label="住址" width="280">
        </el-table-column>
        <el-table-column prop="engageForm" label="合同形式" width="80">
        </el-table-column>
        <el-table-column prop="tiptopDegree" label="学历" width="60">
        </el-table-column>
        <el-table-column prop="specialty" label="专业" width="150">
        </el-table-column>
        <el-table-column prop="school" label="毕业院校" width="120">
        </el-table-column>
        <el-table-column prop="workState" label="在职状态" width="70">
        </el-table-column>
        <el-table-column prop="beginDate" label="入职日期" width="100">
        </el-table-column>
        <el-table-column prop="conversionTime" label="转正日期" width="100">
        </el-table-column>
        <el-table-column prop="beginContract" label="合同起始日期" width="100">
        </el-table-column>
        <el-table-column prop="endContract" label="合同截止日期" width="100">
        </el-table-column>
        <el-table-column label="合同期限" width="80">
          <template slot-scope="scope">
            <el-tag size="mini">{{ scope.row.contractTerm }}</el-tag>年
          </template>
        </el-table-column>
        <el-table-column fixed="right" label="操作" width="220">
          <template slot-scope="scope">
            <el-button style="padding: 7px;" size="mini" @click="showEditEmp(scope.row)">编辑</el-button>
            <el-button style="padding: 7px;" size="mini" type="primary">查看高级资料</el-button>
            <el-button style="padding: 7px;" size="mini" type="danger" @click="doDeleteEmp(scope.row)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>

      <div style="display: flex;justify-content: flex-end ;margin-top: 7px;">
        <el-pagination background @current-change="currentChange" @size-change="sizeChange"
          layout="sizes, prev, pager, next, jumper, ->, total" :total="total">
        </el-pagination>
      </div>
      <!-- dialog 弹出框 -->
      <el-dialog :title="title" :visible.sync="dialogVisible" width="70%">
        <div>
          <el-form :model="emp" ref="empFrom" :rules="rules">
            <el-row>
              <el-col :span="6">
                <el-form-item label="姓名" prop="name">
                  <el-input class="add_emp_left" size="mini" prefix-icon="el-icon-edit" v-model="emp.name"
                    placeholder="请输入员工姓名"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="5">
                <el-form-item label="性别" prop="gender">
                  <el-radio-group size="mini" v-model="emp.gender">
                    <el-radio size="mini" label="男"></el-radio>
                    <el-radio size="mini" label="女"></el-radio>
                  </el-radio-group>
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="出生日期" prop="birthday">
                  <el-date-picker size="mini" class="add_emp_left" style="width: 150px;" type="date" placeholder="选择日期"
                    value-format="yyyy-MM-dd" v-model="emp.birthday"></el-date-picker>
                </el-form-item>
              </el-col>
              <el-col :span="7">
                <el-form-item label="政治面貌" prop="politicId">
                  <el-select size="mini" class="add_emp_right" v-model="emp.politicId" placeholder="政治面貌">
                    <el-option v-for="(item, index) in politicsstatus" :key="index" :label="item.name"
                      :value="item.id"></el-option>
                  </el-select>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="6">
                <el-form-item label="民族" prop="nationId">
                  <el-select size="mini" class="add_emp_left" v-model="emp.nationId" placeholder="民族">
                    <el-option v-for="(item, index) in nations" :key="index" :label="item.name"
                      :value="item.id"></el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="5">
                <el-form-item label="籍贯" prop="nativePlace">
                  <el-input class="add_emp_left" size="mini" prefix-icon="el-icon-edit" v-model="emp.nativePlace"
                    placeholder="籍贯"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="电子邮箱" prop="email">
                  <el-input class="add_emp_left" size="mini" prefix-icon="el-icon-message" v-model="emp.email"
                    placeholder="电子邮箱"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="7">
                <el-form-item label="联系地址" prop="address">
                  <el-input class="add_emp_right" size="mini" prefix-icon="el-icon-location-outline"
                    v-model="emp.address" placeholder="联系地址"></el-input>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="6">
                <el-form-item label="职位" prop="posId">
                  <el-select size="mini" class="add_emp_left" v-model="emp.posId" placeholder="职位">
                    <el-option v-for="(item, index) in positions" :key="index" :label="item.name"
                      :value="item.id"></el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="5">
                <el-form-item label="职称" prop="jobLevelId">
                  <el-select size="mini" class="add_emp_left" v-model="emp.jobLevelId" placeholder="职称">
                    <el-option v-for="(item, index) in joblevels" :key="index" :label="item.name"
                      :value="item.id"></el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="所属部门" prop="departmentId">
                  <el-popover placement="bottom" title="请选择部门" width="200" trigger="manual" v-model="depVisible">
                    <el-tree :data="departments" :props="defaultProps" default-expand-all @node-click="handleNodeClick">
                    </el-tree>
                    <div slot="reference" class="add_emp_dep" @click="showDepView">
                      <span class="dep_con">{{ inputDepName }}</span>
                      <i class="el-icon-arrow-down ic_right"></i>
                    </div>
                  </el-popover>
                </el-form-item>
              </el-col>
              <el-col :span="7">
                <el-form-item label="电话号码" prop="phone">
                  <el-input class="add_emp_right" size="mini" prefix-icon="el-icon-phone-outline" v-model="emp.phone"
                    placeholder="电话号码"></el-input>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="6">
                <el-form-item label="工号" prop="workID">
                  <el-input class="add_emp_left" size="mini" prefix-icon="el-icon-edit" v-model="emp.workID"
                    placeholder="工号" disabled></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="5">
                <el-form-item label="学历" prop="tiptopDegree">
                  <el-select size="mini" class="add_emp_left" v-model="emp.tiptopDegree" placeholder="学历">
                    <el-option v-for="(item, index) in tiptopDegrees" :key="index" :label="item"
                      :value="item"></el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="毕业院校" prop="school">
                  <el-input class="add_emp_left" size="mini" prefix-icon="el-icon-edit" v-model="emp.school"
                    placeholder="毕业院校"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="7">
                <el-form-item label="专业名称" prop="specialty">
                  <el-input class="add_emp_right" size="mini" prefix-icon="el-icon-edit" v-model="emp.specialty"
                    placeholder="专业名称"></el-input>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="6">
                <el-form-item label="入职日期" prop="beginDate">
                  <el-date-picker size="mini" class="add_emp_date" type="date" style="width: 140px;" placeholder="入职日期"
                    value-format="yyyy-MM-dd" v-model="emp.beginDate"></el-date-picker>
                </el-form-item>
              </el-col>
              <el-col :span="5">
                <el-form-item label="转正日期" prop="conversionTime">
                  <el-date-picker size="mini" class="add_emp_date" type="date" style="width: 130px;" placeholder="转正日期"
                    value-format="yyyy-MM-dd" v-model="emp.conversionTime"></el-date-picker>
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="合同起始日期" prop="beginContract">
                  <el-date-picker size="mini" class="add_emp_date" style="width: 140px;" type="date"
                    placeholder="合同起始日期" value-format="yyyy-MM-dd" v-model="emp.beginContract"></el-date-picker>
                </el-form-item>
              </el-col>
              <el-col :span="7">
                <el-form-item label="合同截止日期" prop="endContract">
                  <el-date-picker size="mini" class="add_emp_dater" style="width: 140px;" type="date"
                    placeholder="合同截止日期" value-format="yyyy-MM-dd" v-model="emp.endContract"></el-date-picker>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="8">
                <el-form-item label="身份证号" prop="idCard">
                  <el-input class="add_emp_id" size="mini" prefix-icon="el-icon-edit" v-model="emp.idCard"
                    placeholder="身份证号"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="聘用形式" prop="engageForm">
                  <el-radio-group size="mini" v-model="emp.engageForm">
                    <el-radio size="mini" label="劳动合同"></el-radio>
                    <el-radio size="mini" label="劳务合同"></el-radio>
                  </el-radio-group>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="婚姻状况" prop="wedlock">
                  <el-radio-group size="mini" v-model="emp.wedlock">
                    <el-radio size="mini" label="已婚"></el-radio>
                    <el-radio size="mini" label="未婚"></el-radio>
                    <el-radio size="mini" label="离异"></el-radio>
                  </el-radio-group>
                </el-form-item>
              </el-col>
            </el-row>
          </el-form>
        </div>
        <span slot="footer" class="dialog-footer">
          <el-button @click="dialogVisible = false">取 消</el-button>
          <el-button type="primary" @click="doAddEmp">确 定</el-button>
        </span>
      </el-dialog>


    </div>


  </div>
</template>

<script>
export default {
  data() {
    return {
      title: '',
      // tree 树形控件
      defaultProps: {
        children: 'children',
        label: 'name'
      },
      // 所属部门弹框控制
      depVisible: false,
      // 员工数据
      emps: [],
      // 懒加载
      loading: false,
      // 总条数
      total: 0,
      // 起始页
      currentPage: 1,
      // 每页显示的条数
      size: 10,
      // 员工名字
      empName: '',
      // 弹框
      dialogVisible: false,
      // 添加员工
      emp: {
        id: null,
        name: '',
        gender: '',
        birthday: '',
        idCard: '',
        wedlock: '',
        // 名族id
        nationId: null,
        // 籍贯
        nativePlace: '',
        politicId: null,
        email: '',
        phone: '',
        address: '',
        departmentId: null,
        jobLevelId: null,
        posId: null,
        engageForm: '',
        tiptopDegree: '',
        specialty: '',
        school: '',
        beginDate: '',
        workState: '在职',
        workID: '',
        contractTerm: null,
        conversionTime: '',
        notWorkDate: null,
        beginContract: '',
        endContract: '',
        workAge: null,
        salaryId: null,
      },
      // 政治面貌
      politicsstatus: [],
      // 民族
      nations: [],
      // 职位
      positions: [],
      // 职称
      joblevels: [],
      // 部门
      departments: [],
      // 学历
      tiptopDegrees: [
        "博士",
        "硕士",
        "本科",
        "大专",
        "高中",
        "初中",
        "小学",
        "其他",
      ],
      rules: {
        name: [{ required: true, message: "请输入员工姓名", trigger: "blur" }],
        gender: [{ required: true, message: "请选择性别", trigger: "blur" }],
        birthday: [
          { required: true, message: "请选择出生日期", trigger: "blur" },
        ],
        idCard: [
          { required: true, message: "请输入身份证号", trigger: "blur" },
          {
            pattern:
              /^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/,
            message: "身份证号格式有误",
            trigger: "blur",
          },
        ],
        wedlock: [
          { required: true, message: "请选择婚姻状况", trigger: "blur" },
        ],
        nationId: [{ required: true, message: "请选择民族", trigger: "blur" }],
        nativePlace: [
          { required: true, message: "请输入籍贯", trigger: "blur" },
        ],
        politicId: [
          { required: true, message: "请选择政治面貌", trigger: "blur" },
        ],
        email: [
          { required: true, message: "请输入邮箱", trigger: "blur" },
          { type: "email", message: "邮箱格式不正确", trigger: "blur" },
        ],
        phone: [
          { required: true, message: "请输入手机号", trigger: "blur" },
          {
            pattern:
              /^(?:(?:\+|00)86)?1(?:(?:3[\d])|(?:4[5-79])|(?:5[0-35-9])|(?:6[5-7])|(?:7[0-8])|(?:8[\d])|(?:9[189]))\d{8}$/,
            message: "手机号格式有误",
            trigger: "blur",
          },
        ],
        address: [{ required: true, message: "请输入地址", trigger: "blur" }],
        departmentId: [
          { required: true, message: "请选择部门", trigger: "blur" },
        ],
        jobLevelId: [
          { required: true, message: "请选择职称", trigger: "blur" },
        ],
        posId: [{ required: true, message: "请选择职位", trigger: "blur" }],
        engageForm: [
          { required: true, message: "请选择聘用形式", trigger: "blur" },
        ],
        tiptopDegree: [
          { required: true, message: "请选择学历", trigger: "blur" },
        ],
        specialty: [{ required: true, message: "请输入专业", trigger: "blur" }],
        school: [
          { required: true, message: "请输入毕业院校", trigger: "blur" },
        ],
        beginDate: [
          { required: true, message: "请选择入职日期", trigger: "blur" },
        ],
        workState: [
          { required: true, message: "请选择工作状态", trigger: "blur" },
        ],
        workID: [{ required: true, message: "请输入工号", trigger: "blur" }],
        contractTerm: [
          { required: true, message: "请选择合同期限", trigger: "blur" },
        ],
        conversionTime: [
          { required: true, message: "请选择转正日期", trigger: "blur" },
        ],
        notWorkDate: [
          { required: true, message: "请输入离职日期", trigger: "blur" },
        ],
        beginContract: [
          { required: true, message: "请选择合同起始日期", trigger: "blur" },
        ],
        endContract: [
          { required: true, message: "请选择合同结束日期", trigger: "blur" },
        ],
        workAge: [{ required: true, message: "请输入工龄", trigger: "blur" }],
      },
      // 所属部门
      inputDepName: '',
      // 上传文件的文本
      uploadText: "导入数据",
      // 上传文件图标
      uploadIcon: "el-icon-upload",
      // 导入按钮禁用
      importDataDisables: false,
      // 头部
      hearder: {
        Authorization: window.sessionStorage.getItem("tokenStr")
      },
      // 高级搜索的展示与隐藏
      advanceSearchBtn: false,
      // 高级搜索值
      searchValue: {
        politicId: null,
        nationId: null,
        posId: null,
        // 职称
        jobLevelId: null,
        // 聘用形式
        engageForm: '',
        // 部门
        departmentId: null,
        // 范围
        beginDateScope: '',
      },
      depVisible2: false,
      inputDepName2: '',

    }
  },
  methods: {
    // 上传失败
    onError() {
      this.uploadIcon = 'el-icon-upload';
      this.uploadText = '导入数据';
      this.importDataDisables = false;
    },
    // 上传成功
    onSuccess() {
      this.uploadIcon = 'el-icon-upload';
      this.uploadText = '导入数据';
      this.initEmps();
      this.importDataDisables = false;
    },
    // 导入文件触发
    beforeUpload() {
      this.uploadIcon = 'el-icon-loading';
      this.uploadText = '正在导入';
      this.importDataDisables = true;
    },
    // 导出数据
    expostData() {
      this.downloadRequest('/employee/basic/export');
    },
    // 删除员工
    doDeleteEmp(data) {
      this.$confirm('此操作将永久删除该' + data.name + ', 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        // 删除部门
        this.deleteRequest('/employee/basic/' + data.id).then(resp => {
          if (resp) {
            this.initEmps();
          }
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });
    },
    // 编辑框展示
    showEditEmp(data) {
      this.title = '编辑员工信息';
      this.emp = data;
      this.inputDepName = data.department.name;
      // 获取职位
      this.initPositions();
      this.dialogVisible = true;
    },
    searchHandleNodeClick(data) {
      this.inputDepName2 = data.name;
      this.searchValue.departmentId = data.id;
      this.depVisible2 = !this.depVisible2;
    },
    // 关闭树形控件
    handleNodeClick(data) {
      this.inputDepName = data.name;
      this.emp.departmentId = data.id;
      this.depVisible = !this.depVisible
    },
    // 显示部门
    showDepView() {
      this.depVisible = !this.depVisible;
    },
    showDepView2() {
      this.depVisible2 = !this.depVisible2;
    },
    // 获取员工最大工号
    getmaxWorkID() {
      this.getRequest('/employee/basic/maxWorkID').then(resp => {
        if (resp) {
          this.emp.workID = resp.obj;
        }
      })
    },
    // 添加员工
    doAddEmp() {
      // id有值代表修改
      if (this.emp.id) {
        this.$refs["empFrom"].validate((valid) => {
          if (valid) {
            console.log(this.emp);
            this.putRequest('/employee/basic/', this.emp).then((resp) => {
              if (resp) {
                this.initEmps();
                this.dialogVisible = false;
              }
            });
          } else {
            this.$message.error("请输入所有字段！");
            return false;
          }
        });
      } else {
        this.$refs["empFrom"].validate((valid) => {
          if (valid) {
            console.log(this.emp);
            this.postRequest('/employee/basic/', this.emp).then((resp) => {
              if (resp) {
                this.initEmps();
                this.dialogVisible = false;
              }
            });
          } else {
            this.$message.error("请输入所有字段！");
            return false;
          }
        });
      }

    },
    // 初始化职位
    initPositions() {
      this.getRequest('/employee/basic/positions').then((resp) => {
        this.positions = resp;
      });
    },
    // 获取所有名族
    initData() {
      // 民族
      if (!window.sessionStorage.getItem("nations")) {
        this.getRequest('/employee/basic/nations').then((resp) => {
          if (resp) {
            this.nations = resp;
            window.sessionStorage.setItem("nations", JSON.stringify(resp));
          }
        });
      } else {
        this.nations = JSON.parse(window.sessionStorage.getItem("nations"));
      }
      // 所有职称
      if (!window.sessionStorage.getItem("joblevels")) {
        this.getRequest('/employee/basic/joblevels').then((resp) => {
          if (resp) {
            this.joblevels = resp;
            window.sessionStorage.setItem("joblevels", JSON.stringify(resp));
          }
        });
      } else {
        this.joblevels = JSON.parse(window.sessionStorage.getItem("joblevels"));
      }
      // 所有政治面貌
      if (!window.sessionStorage.getItem("politicsstatus")) {
        this.getRequest('/employee/basic/politicsstatus').then((resp) => {
          if (resp) {
            this.politicsstatus = resp;
            window.sessionStorage.setItem("politicsstatus", JSON.stringify(resp));
          }
        });
      } else {
        this.politicsstatus = JSON.parse(window.sessionStorage.getItem("politicsstatus"));
      }
      // 所有员工部门
      if (!window.sessionStorage.getItem("departments")) {
        this.getRequest('/employee/basic/deps').then((resp) => {
          if (resp) {
            this.departments = resp;
            window.sessionStorage.setItem("departments", JSON.stringify(resp));
          }
        });
      } else {
        this.departments = JSON.parse(window.sessionStorage.getItem("departments"));
      }
    },
    // 显示添加弹框
    showAddEmp() {
      this.title = '添加员工';

      this.emp = {
        id: null,
        name: '',
        gender: '',
        birthday: '',
        idCard: '',
        wedlock: '',
        // 名族id
        nationId: null,
        // 籍贯
        nativePlace: '',
        politicId: null,
        email: '',
        phone: '',
        address: '',
        departmentId: null,
        jobLevelId: null,
        posId: null,
        engageForm: '',
        tiptopDegree: '',
        specialty: '',
        school: '',
        beginDate: '',
        workState: '在职',
        workID: '',
        contractTerm: null,
        conversionTime: '',
        notWorkDate: null,
        beginContract: '',
        endContract: '',
        workAge: null,
        salaryId: null,
      }
      this.inputDepName = '';
      // 获取员工最大编号
      this.getmaxWorkID();

      this.dialogVisible = true;
    },
    // 起始页变化我们就发送请求去查询
    currentChange(currentPage) {
      this.currentPage = currentPage
      this.initEmps();
    },
    sizeChange(size) {
      this.size = size;
      this.initEmps();
    },
    initEmps(type) {
      this.loading = true;
      let url = '/employee/basic/?currentPage=' + this.currentPage + '&size=' + this.size;
      // type 表示是高级搜索
      if (type && type == 'advanced') {
        // 政治面貌
        if (this.searchValue.politicId) {
          url += '&politicId=' + this.searchValue.politicId;
        }
        // 名族
        if (this.searchValue.nationId) {
          url += '&nationId=' + this.searchValue.nationId;
        }
        // 职称
        if (this.searchValue.jobLevelId) {
          url += '&jobLevelId=' + this.searchValue.jobLevelId;
        }
        // 职位
        if (this.searchValue.posId) {
          url += '&posId=' + this.searchValue.posId;
        }
        // 聘用形式
        if (this.searchValue.engageForm) {
          url += '&engageForm=' + this.searchValue.engageForm;
        }
        // 部门
        if (this.searchValue.departmentId) {
          url += '&departmentId=' + this.searchValue.departmentId;
        }
        // 入职日期
        if (this.searchValue.beginDateScope) {
          url += '&beginDateScope=' + this.searchValue.beginDateScope;
        }
      } else {
        url += "&name=" + this.empName;
      }
      this.getRequest(url).then(resp => {
        this.loading = false;
        if (resp) {
          this.emps = resp.data;
          this.total = resp.total;
        }
      });

    }
  },
  mounted() {
    this.initEmps();
    this.initData();
    // 获取职位
    this.initPositions();
  }
}
</script>

<style>
.emp_search_inp {
  width: 300px;
  margin-right: 10px;
}

::-webkit-scrollbar {
  display: block;
}

.add_emp_left {
  width: 150px;
}

.add_emp_date {
  width: 120px;
}

.add_emp_dater {
  width: 180px;
}

.add_emp_right {
  width: 200px;
}

.add_emp_id {
  width: 240px;
}

.add_emp_dep {
  display: inline-block;
  width: 115px;
  height: 20px;
  border: 1px solid #dcdfe6;
  border-radius: 5px;
  margin-top: 3px;
  font-size: 12px;
  color: #606266;
  padding: 0px 0px 7px 14px;
}

/* 设置持续时间和动画函数 */
.slide-fade-enter-active {
  transition: all .8s ease;
}

.slide-fade-leave-active {
  transition: all .8s cubic-bezier(1.0, 0.5, 0.8, 1.0);
}

.slide-fade-enter,
.slide-fade-leave-to

/* .slide-fade-leave-active for below version 2.1.8 */
  {
  transform: translateX(10px);
  opacity: 0;
}
</style>